﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using Model;

namespace BLL
{
  public partial  class UsersInfoManager
    {


      //根据用户编号 获取信息
      public UsersInfo getByUserId( string UserId)
      {
          return db.GetAll().FirstOrDefault(p => p.memberId == UserId);
      }
      // 获取用户列表中最大的用户id
      public string getMaxUserId()
      {
          return db.GetAll().OrderByDescending(p => p.memberId).ToList<UsersInfo>()[0].memberId;
      }
      //根据用户编号删除用户
      public void DelByUserId(string UserId)
      {
          UsersInfo UI = db.GetAll().Where(p => p.memberId == UserId).FirstOrDefault();
          db.Delete(UI);
          db.SaveChanges();
      }

      /// <summary>
      /// 根据条件查找用户
      /// </summary>
      /// <param name="UserId"></param>
      /// <param name="UserName"></param>
      /// <param name="sex"></param>
      /// <param name="mobile"></param>
      /// <returns></returns>
      public IQueryable<UsersInfo> SelectByInput(string UserId, string UserName, string sex, string mobile)
      {
          ZG_OAEntities ds = new ZG_OAEntities();
          var query = from obj in ds.UsersInfo orderby obj.id descending select obj;
          if (!string.IsNullOrEmpty(UserId))
          {
              query = from obj in query where obj.memberId == UserId orderby obj.id descending select obj;

          }
          if (!string.IsNullOrEmpty(UserName))
          {
              query = from obj in query where obj.memberName == UserName orderby obj.id descending select obj;

          }
          if (!string.IsNullOrEmpty(sex))
          {
              query = from obj in query where obj.sex == sex orderby obj.id descending select obj;

          }
          if (!string.IsNullOrEmpty(mobile))
          {
              query = from obj in query where obj.mobile == mobile orderby obj.id descending select obj;

          }
          return query;
      }

    }
}
